package com.zyx.mysql.config;

import com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration;
import com.zyx.mysql.interceptor.QueryInterceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: TODO
 * @Author: ZYX
 * @Date: 2021/11/16 15:21
 * @Version: 1.0
 */
//@Configuration
//@AutoConfigureAfter(PageHelperAutoConfiguration.class)
public class QuerySqlConfinguration {

    @Resource
    private List<SqlSessionFactory> sqlSessionFactoryList;

    @PostConstruct
    public void addMyInterceptor(){

        QueryInterceptor queryInterceptor = new QueryInterceptor();
        sqlSessionFactoryList.forEach(sqlSessionFactory -> sqlSessionFactory.getConfiguration().addInterceptor(queryInterceptor));

    }

}
